package com.augrain.microframework.limit.annotation;


import com.augrain.microframework.limit.model.LimitType;
import com.augrain.microframework.limit.breaker.CircuitBreaker;
import com.augrain.microframework.limit.breaker.DefaultCircuitBreaker;

import java.lang.annotation.*;

/**
 * @author biaoy
 * @since 2020/12/22
 * 用于分布式限流
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface RateLimiter {

    /**
     * Key的prefix
     */
    String prefix() default "";

    /**
     * 限流规则
     */
    RateRule[] rules() default {};

    /**
     * 过期时间,默认1s
     */
    int timeout() default 1;

    /**
     * max timeout时间内最大请求数
     */
    long max() default Long.MAX_VALUE;

    /**
     * 限流类型
     */
    LimitType limitType() default LimitType.METHOD;

    /**
     * 熔断策略，默认策略为抛出RequestExceedLimitException异常
     */
    Class<? extends CircuitBreaker> breaker() default DefaultCircuitBreaker.class;
}
